package main

import (
  "fmt"
)

func testPoint1() {
  var a int32

  fmt.Printf("the addr of a :%p\n", &a) //the addr of a :0xc00000a0a0

  //================================================================================
  var b *int32
  if b == nil {
    fmt.Println("b is nil addr")
  }
  fmt.Printf("the addr of b: %p, b:%p\n", &b /*变量b本身的地址*/, b /*变量存储的东东*/) //the addr of a :0xc0000a2058the addr of b: 0xc0000cc020, b:0x0
  fmt.Printf("the addr of b: %p, b:%v\n", &b, b)                          //the addr of a :0xc0000a2058the addr of b: 0xc0000cc020, b:<nil>

  //如果一个指针没有初始化 接下来再赋值是会报错的
  //*b = 100 //panic: runtime error: invalid memory address or nil pointer dereference

  //================================================================================
  b = &a //将变量a的地址赋给了变量b存储
  fmt.Printf(
    "the addr of b: %p, b:%v\n",
    &b /*变量b本身的地址*/,
    b  /*变量b存储的变量a的地址*/) //the addr of b: 0xc000006030, b:0xc00000a0a0
}

func testPoint2() {
  //==================================================================================
  //如何通过指针变量 操纵 变量指向的地址里面的值？

  var a int = 200
  var b *int = &a

  fmt.Printf("b指向的地址存储的值是 %d\n",*b)//b指向的地址存储的值是 200

  *b = 1000
  fmt.Printf("b指向的地址存储的值是 %d\n",*b)//b指向的地址存储的值是 1000
  fmt.Printf("a=%d\n",a) //a=1000

}

func main() {
  //testPoint1()

  testPoint2()
}
